package ct.zxd.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TUserDao {
	
	/**
	 * 判断用户是否已经在用户表中
	 * @param openid
	 * @return 用户名
	 * @throws SQLException
	 */
	public String getUserName(String openid) throws SQLException{
		Connection conn=null;
		String result="";
		conn=DBconn.getconn();
		if(conn!=null){
			String sql="select icon from user where id=?";
			PreparedStatement pstm=conn.prepareStatement(sql);
			pstm.setString(1, openid);
		    ResultSet rs=pstm.executeQuery();	
		    if(rs.next())result=rs.getString(1);
		    DBconn.closeconn(conn);
		}
		return result;
	}
	
	public int insertUserMark(String id , String name , String icon) {
		Connection conn = null ;
		PreparedStatement pstm = null ;
		int count = 0 ;
		try {
			conn = DBconn.getconn();
			String sql = "insert into user (id , name , icon) values (?,?,?)" ;
			pstm = conn.prepareStatement(sql) ;
			pstm.setString(1, id);
			pstm.setString(2, name);
			pstm.setString(3, icon);
			count = pstm.executeUpdate() ;
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			if(!(conn == null)) {
				DBconn.closeconn(conn);
			}
		}	
		return count ;
	}
}


//Connection conn = null ;
//PreparedStatement pstm = null ;
//try {
//	conn = DBconn.getconn();
//String sql = "" ;
//pstm = conn.prepareStatement(sql) ;
//
//}catch(Exception e) {
//	e.printStackTrace();
//}finally {
//	if(!(conn == null)) {
//		DBconn.closeconn(conn);
//	}
//}
//}